const api=require("../../api/index.js");

// pages/home/home.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
      types:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    
      this.loadHotFilms();
      this.loadLatestFilms();
  },
  doSearch(e){
      wx.navigateTo({
        url: `/pages/search/search?q=${e.detail.value}&name=${e.detail.value} '电影列表'`,
      })
  },
  async loadHotFilms(){
     let res= await api.loadHotFilms();
     console.log(res);
     let filmType={
        title:res.data.subject_collection.name,
        list:res.data.subject_collection_items,
        funName:"loadHotFilms"
     };
     this.setData({
       "types[0]":filmType
     });
  },
  async loadLatestFilms(){
    let res= await api.loadLatestFilms();
    let filmType={
       title:res.data.subject_collection.name,
       list:res.data.subject_collection_items,
       funName:"loadLatestFilms"
    };
    this.setData({
      "types[1]":filmType
    });
 }

})